﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<script>
			//请求地址 http://xxxxxxxxxxxxxxx:8080/AJAX/checkname?regname=需要验证的用户名
			//该地址验证所提交的用户名是否存在，如果存在，返回字符串yes，不存在返回no
			window.onload = function(){	
				var username = document.getElementById("username");
				username.onblur = function(){
					var req = null;
					if(window.ActiveXObject){
						req = new ActiveXObject("Msxml2.XMLHTTP");
					} else {
						req = new XMLHttpRequest();
					}
					req.open("get","http://192.168.87.79/AJAX/checkname?regname="+username.value,true);
					req.onreadystatechange = function(){
						if(req.readyState == 4){
							if(req.responseText == "yes"){
								alert("用户已被注册！请换一个名字");
							}
						}
					}
					req.send();
				}
			}
		</script>
	</head>

	<body>
		姓名:<input id="username" type="text" /><br>
		密码:<input type="password"/><br>
		<button onclick="check()">注册</button>
		
	</body>

</html>



























